//
//  AppViewController.m
//  drawacartoon
//
//  Created by Ji Hu on 12-7-25.
//  Copyright (c) 2012年 爱辅导. All rights reserved.
//

#import "AppViewController.h"
#import "Log.h"
#import "PersistenceCenter.h"

@interface AppViewController ()

@end

@implementation AppViewController

@synthesize mainViewController=_mainViewController,drawCartoonViewController=_drawCartoonViewController;

-(void)didReceiveMemoryWarning{
    [Log warning:@"appview controller receive memory warning!"];
}

-(void)terminate{
    NSLog(@"application terminate.");
    [[PersistenceCenter defaultCenter] savePersistence];
}

-(void)dealloc{
    self.mainViewController=nil;
    self.drawCartoonViewController=nil;
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    if (self.mainViewController==nil) {
        _mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
        _mainViewController.delegate=self;
        [self.view addSubview:_mainViewController.view];
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

-(void)exitDrawCartoon{
    
    [_drawCartoonViewController release];
    _drawCartoonViewController = nil;
    
    [self.view bringSubviewToFront:_mainViewController.view];
    
}

-(void)openDrawCartoonViewController:(id)params{
    
    if (_drawCartoonViewController==nil) {
        _drawCartoonViewController = [[DrawCartoonViewController alloc] initWithNibName:@"DrawCartoonViewController" bundle:nil];
        _drawCartoonViewController.drawCartoonDelegate=self;
        [self.view addSubview:_drawCartoonViewController.view];
    }
    
    [self.view bringSubviewToFront:_drawCartoonViewController.view];
}

@end
